﻿using AnQinFrameWorkAPI.Entity.BaseInfo.DTO.Department;
using AnQinFrameWorkAPI.Entity.BaseInfo.DTO.Staff;
using AnQinFrameWorkAPI.Entity.BaseInfo.Entity;
using AnQinFrameWorkAPI.Entity.BaseInfo.View.Department;
using AnQinFrameWorkAPI.Entity.BaseInfo.View.Staff;
using AutoMapper;

namespace AnQinFrameWorkAPI.Common.Mapper;

public class BaseInfoMapper : Profile
{
    public BaseInfoMapper()
    {
        //全局配置
        CreateMap<Guid?, string>().ConvertUsing(src =>
            src == null || src == Guid.Empty ? null : src.Value.ToString());

        #region 基础

        #region 员工管理

        CreateMap<StaffAddDTO, StaffModel>();
        CreateMap<StaffUpdateDTO, StaffModel>();
        CreateMap<StaffModel, StaffView>()
            .ForMember(a => a.StaffRoleList,
                opt => opt.MapFrom(src => src.StaffRoleList.Select(b => b.RoleId.ToString()).ToArray()));

        #endregion

        #region 部门管理

        CreateMap<DepartmentAddDTO, DepartmentModel>();
        CreateMap<DepartmentUpdateDTO, DepartmentModel>();
        CreateMap<DepartmentModel, DepartmentView>()
            .ForMember(a => a.SuperiorName,
                opt => opt.MapFrom(src => src.Department.Name));

        #endregion

        #endregion
    }
}